/*

Author   : chaos

FileName : obj_arg.cpp

Date     : 12/08/17 13:17:01

*/
#include <iostream>
#include <cstring>

using namespace std;

class String
{
    private:
        char * string;
        int len;
    public:
        String(const char * i_string);
        String(String &);
        ~String();
        void show_string();
};

void String::show_string()
{ cout << "string :" << string << " length :" << len << endl; }

String::String(const char * i_string)
{
    cout << " Constructor is called !" << endl;
    len = strlen(i_string);
    string = new char[len + 1];
    strcpy(string , i_string);
}


String::String(String & a_string):len (a_string.len)
{
    cout << " Copy constructor is called !" << endl;
    string = new char [len + 1];
    strcpy(string,a_string.string);
}

String::~String()
{
    cout << "Destructor is called " << endl;
    delete [] string;
}
int main(int argc ,char *argv[])
{
    void call_by_val(String);

    void call_by_ref(String &);

    String A_String("My string");

    cout << endl << " **************call by reference************" << endl;
    cout << " Before executing function ..." << endl;
    call_by_ref(A_String);
    cout << endl << "After executing function ... " << endl;

    cout << endl << "***********call by value ************" << endl;
    cout << "Before executing function ... " << endl;
    call_by_val(A_String);

    cout << endl << " ********************************" << endl;
    cout << endl << "After executing function ..." << endl;
    return 0;
}

void call_by_ref(String &aString)
{ cout << endl << " Executing call_by_ref function ..." << endl; }

void call_by_val(String aString)
{ cout << endl << "Executing call_by_val function ..." << endl; }
